package cn.bigcontainer.alt.sys.exception;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.stereotype.Component;

import cn.bigcontainer.alt.common.exception.BigException;
import cn.bigcontainer.alt.common.exception.BigResultCode;
import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
public class AjaxJsonExceptionHandler implements MethodInterceptor {

	@Override
	public Object invoke(MethodInvocation mi) throws Throwable {
		try {
			return mi.proceed();
		} catch (BigException e) {
			log.error("", e);
			return e.getCode();
		} catch (Exception e) {
			log.error("", e);
			return BigResultCode.getUnknownCode().setMsg(e.getMessage());
		}
	}

}
